import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'
import type { CoreTree } from '/@/tool/CoreTree'

import postService from '/@/api/cn/core/sign/postService'

import type { Post } from '/@/model/cn/core/sign/eo/Post'
import type { PostQO } from '/@/model/cn/core/sign/qo/PostQO'
import type { PostVO } from '/@/model/cn/core/sign/vo/PostVO'

interface PostState {
}

export const usePostStore = defineStore({
  id: 'post',
  state: (): PostState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<PostVO>): Promise<Res<PostVO>> {
      return new Promise<Res<PostVO>>((resolve, reject) => {
        postService.save(param).then((res: AxiosResponse<Res<PostVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<Post>): Promise<Res<Post>> {
      return new Promise<Res<Post>>((resolve, reject) => {
        postService.saveBatch(param).then((res: AxiosResponse<Res<Post>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<PostVO>): Promise<Res<PostVO>> {
      return new Promise<Res<PostVO>>((resolve, reject) => {
        postService.update(param).then((res: AxiosResponse<Res<PostVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<Post>): Promise<Res<Post>> {
      return new Promise<Res<Post>>((resolve, reject) => {
        postService.updateBatch(param).then((res: AxiosResponse<Res<Post>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<Post>): Promise<Res<Post>> {
      return new Promise<Res<Post>>((resolve, reject) => {
        postService.remove(param).then((res: AxiosResponse<Res<Post>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<Post>): Promise<Res<Post>> {
      return new Promise<Res<Post>>((resolve, reject) => {
        postService.removeBatch(param).then((res: AxiosResponse<Res<Post>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<PostQO>): Promise<Res<Post>> {
      return new Promise<Res<Post>>((resolve, reject) => {
        postService.count(param).then((res: AxiosResponse<Res<Post>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<PostQO>): Promise<Res<Post>> {
      return new Promise<Res<Post>>((resolve, reject) => {
        postService.pk(param).then((res: AxiosResponse<Res<Post>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<PostQO>): Promise<Res<Post>> {
      return new Promise<Res<Post>>((resolve, reject) => {
        postService.query(param).then((res: AxiosResponse<Res<Post>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<PostQO>): Promise<Res<Post>> {
      return new Promise<Res<Post>>((resolve, reject) => {
        postService.paging(param).then((res: AxiosResponse<Res<Post>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<PostQO>): Promise<Res<PostVO>> {
      return new Promise<Res<PostVO>>((resolve, reject) => {
        postService.countVo(param).then((res: AxiosResponse<Res<PostVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<PostQO>): Promise<Res<PostVO>> {
      return new Promise<Res<PostVO>>((resolve, reject) => {
        postService.pkVo(param).then((res: AxiosResponse<Res<PostVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<PostQO>): Promise<Res<PostVO>> {
      return new Promise<Res<PostVO>>((resolve, reject) => {
        postService.queryVo(param).then((res: AxiosResponse<Res<PostVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<PostQO>): Promise<Res<PostVO>> {
      return new Promise<Res<PostVO>>((resolve, reject) => {
        postService.pagingVo(param).then((res: AxiosResponse<Res<PostVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    getOrgPostTreeData(param: Param<PostQO>): Promise<Res<CoreTree<any>>> {
      return new Promise<Res<CoreTree<any>>>((resolve, reject) => {
        postService.getOrgPostTreeData(param).then((res: AxiosResponse<Res<CoreTree<any>>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function usePostStoreWithout() {
  return usePostStore(store)
}
